using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace OpenRay
{
	public class PlaneGeometry : Geometry
	{		
		public PlaneGeometry ( IList<Point> v, IList<Vector> n, IList<Material> m )
			: base ( v, n, m )
		{
			Debug.Assert( v.Count == 1, "Incorrect number of vertices provided" );
			Debug.Assert( n.Count == 1, "Incorrect number of normals provided" );
			Debug.Assert( m.Count == 1, "Incorrect number of materials provided" );
		}
		
		public override IList<GeometryHit> Trace(Ray r)
		{
			List<GeometryHit> ret = new List<GeometryHit>();			
			
			Vector temp = r.Origin - vertices[0];
			float distance = -Vector.DotProduct( temp, normals[0] ) / Vector.DotProduct( r.Direction, normals[0] );

			if ( distance > Delta )
				ret.Add( new GeometryHit(this, r, distance ) );
			
			return ret;
		}
		
		public override Material Material (Point modelHit, InterpolationData interpolation)
		{
			return materials[0];
		}
		
		public override Vector Normal (Point modelHit, InterpolationData interpolation)
		{
			return normals[0];
		}
		
		public override BoundingBox BoundingBox ()
		{
			return new BoundingBox( new Point( -100, -100, -100), new Point( 100, 100, 100 ) ); 
		}
	}
}

